package com.octopus.optiworks.controller;

import org.apache.commons.lang.math.NumberUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

public class InitProcessValidator extends CommonValidator {
	
	@Override
    public boolean supports(Class<?> aClass) {
        return InitProcessCommand.class.isAssignableFrom(aClass);
    }

	@Override
    public void validate(Object o, Errors errors) {
    	InitProcessCommand command = (InitProcessCommand)o;
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "number", "error.number.empty", "Please specify a number.");
        if(!NumberUtils.isNumber(command.getNumber()))
        	errors.rejectValue( "number", "error.number.invalid", "Please enter a valid number." );
        else if(NumberUtils.createInteger(command.getNumber()) < 1)
        	errors.rejectValue( "number", "error.number.ltone", "Please enter a valid number greater than 1." );
        
        if(!stepValided)
        	return;
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lot", "error.product.length.invalid.lot", "Please specify a lot.");
    }
}
